package com.liesheng.haylou.common.recycleView;

import android.util.SparseArray;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import com.liesheng.haylou.base.BaseVm;

/**
 * Date:2019/11/7
 * <p>
 * Author:wuzhiguang
 * <p>
 * Description:
 */
public class RecyclerViewHolder<T extends ViewDataBinding> extends RecyclerView.ViewHolder {
    private View mConvertView;
    private SparseArray<View> mViews;
    T binding;

    public RecyclerViewHolder( T binding) {
        super(binding.getRoot());
        this.binding = binding;
    }

    public RecyclerViewHolder(View view) {
        super(view);
        this.mConvertView = view;
        this.mViews = new SparseArray();
    }

    public View getConvertView() {
        return this.mConvertView;
    }

    public <T extends View> T getView(int paramInt) {
        View view = this.mViews.get(paramInt);
        if (view == null) {
            view = this.mConvertView.findViewById(paramInt);
            this.mViews.put(paramInt, view);
        }
        return (T)view;
    }

    public RecyclerViewHolder setOnClickListener(int position, View.OnClickListener paramOnClickListener) {
        getView(position).setOnClickListener(paramOnClickListener);
        return this;
    }

    public RecyclerViewHolder setOnLongClickListener(int position, View.OnLongClickListener paramOnLongClickListener) {
        getView(position).setOnLongClickListener(paramOnLongClickListener);
        return this;
    }

    public RecyclerViewHolder setOnTouchListener(int position, View.OnTouchListener paramOnTouchListener) {
        getView(position).setOnTouchListener(paramOnTouchListener);
        return this;
    }
}
